home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Sample Code / Snippets / Networking / TCP Server / interface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  2.5 KB  |  119 lines  |  [TEXT/KAHL]

  1. /*
  2.     TCP Client/Server Queuing Example
  3.     Steve Falkenburg, MacDTS, Apple Computer
  4.     3/11/92
  5.     
  6.     this client/server sample uses MacTCP to implement a simple "greeting" server.  the server
  7.     opens up several listeners on kGreetingPort (1235).  when a client connects, the data entered
  8.     in the greeting dialog is sent to the remote connection, and the connection is closed.
  9.     
  10.     connection management is done through the use of Operating System queues to simplify tracking
  11.     and usage.
  12. */
  13.  
  14.  
  15. #include "const.h"
  16. #include "globals.h"
  17. #include "utils.h"
  18. #include "interface.h"
  19.  
  20.  
  21. /*    initializes the user interface by loading our dialog into memory, and drawing the initial
  22.     queue numbers into the dialog
  23. */
  24.  
  25. void InitInterface(void)
  26. {
  27.     gMainDialog = GetNewDialog(kMainDialog,nil,(WindowPtr)-1L);
  28.     UpdateNumberList();
  29. }
  30.  
  31.  
  32. /*    displays the current values for the number of parameter blocks in each of the queues
  33.     (unused, running, completed)
  34. */
  35.  
  36. void UpdateNumberList(void)
  37. {
  38.     short iType;
  39.     Handle iHndl;
  40.     Rect iRect;
  41.     Str255 iText;
  42.     long lastValue;
  43.     
  44.     GetDItem(gMainDialog,kServicedItem,&iType,&iHndl,&iRect);
  45.     GetIText(iHndl,iText);
  46.     StringToNum(iText,&lastValue);
  47.     if (lastValue!=gServiced) {
  48.         NumToString(gServiced,iText);
  49.         SetIText(iHndl,iText);
  50.     }
  51.     
  52.     GetDItem(gMainDialog,kFreeItem,&iType,&iHndl,&iRect);
  53.     GetIText(iHndl,iText);
  54.     StringToNum(iText,&lastValue);
  55.     if (lastValue!=gFree) {
  56.         NumToString(gFree,iText);
  57.         SetIText(iHndl,iText);
  58.     }
  59.     
  60.     GetDItem(gMainDialog,kRunningItem,&iType,&iHndl,&iRect);
  61.     GetIText(iHndl,iText);
  62.     StringToNum(iText,&lastValue);
  63.     if (lastValue!=gRunning) {
  64.         NumToString(gRunning,iText);
  65.         SetIText(iHndl,iText);
  66.     }
  67.     
  68.     GetDItem(gMainDialog,kCompletedItem,&iType,&iHndl,&iRect);
  69.     GetIText(iHndl,iText);
  70.     StringToNum(iText,&lastValue);
  71.     if (lastValue!=gCompleted) {
  72.         NumToString(gCompleted,iText);
  73.         SetIText(iHndl,iText);
  74.     }
  75.     
  76.     GetDItem(gMainDialog,kGreetingItem,&iType,&iHndl,&iRect);
  77.     GetIText(iHndl,gGreetingData);
  78. }
  79.  
  80.  
  81. /*    handles events important to our dialog
  82. */
  83.  
  84. Boolean HandleDialogEvents(EventRecord *ev)
  85. {
  86.     DialogPtr theDlg;
  87.     short item;
  88.     
  89.     if (!IsDialogEvent(ev))
  90.         return false;
  91.     
  92.     if (DialogSelect(ev,&theDlg,&item)) {
  93.         if (item==kQuitItem)
  94.             gDone = true;
  95.     }
  96.     
  97.     return true;
  98. }
  99.  
  100.  
  101. /*    handles mouse down events.  we only do dragging, and nothing else
  102. */
  103.  
  104. void HandleMouseDown(Point mouseHit)
  105. {
  106.     WindowPtr window;
  107.     Rect limit;
  108.     
  109.     SetRect(&limit,-32000,-32000,32000,32000);
  110.     
  111.     switch (FindWindow(mouseHit,&window)) {
  112.         case inDrag:
  113.             DragWindow(window,mouseHit,&limit);
  114.         case inGoAway:
  115.             if (TrackGoAway(window,mouseHit))
  116.                 gDone = true;
  117.     }
  118. }
  119.